/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelUser.java
 *
 * Created on 08-dic-2011, 17:20:12
 */
package edu.uoc.tdp.client;

import edu.uoc.tdp.common.CommonLib;
import edu.uoc.tdp.common.EIssueException;
//import edu.uoc.tdp.dal.ManagementBookings;
import edu.uoc.tdp.entity.Booking;
import edu.uoc.tdp.entity.User;
import edu.uoc.tdp.i18n.TDPLanguageUtils;
import edu.uoc.tdp.i18n.TDPLanguageConstants;
import edu.uoc.tdp.entity.Resource;
import edu.uoc.tdp.entity.Space;
import java.rmi.RemoteException;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

/**
 *
 * @author tomeu
 */
public class PanelSearch extends javax.swing.JFrame {

    private int activeSpaceId = 0;
    //private ManagementBookings remoto;

    /** Creates new form PanelUser */
    public PanelSearch(Boolean Admin) {

        initComponents();

        // Carregar texts de labels i botons        
        //btnSave.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNSAVE));
        btnCancel.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNCANCEL));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnCancel = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jTextField5 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jtxtDays = new javax.swing.JTextField();
        jtxtFrom = new javax.swing.JFormattedTextField();
        jtxtTo = new javax.swing.JFormattedTextField();
        jcmbUser = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtxtPersons = new javax.swing.JFormattedTextField(new Integer(2));
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        btnCancel.setText("Cancelar");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Recurs", "Unitats Disponibles", "Preu Unitari", "Unitats Reservades", "Preu Total"
            }
        ));
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Reservar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nom aula", "Preu hora", "Preu dia", "Capacitat", "Localitzacio"
            }
        ));
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable2MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jTextField5.setText("0 €");

        jLabel1.setText("Import Total");

        jtxtDays.setText("0");
        jtxtDays.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtDaysActionPerformed(evt);
            }
        });
        jtxtDays.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtxtDaysFocusLost(evt);
            }
        });

        jtxtFrom.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("yyyy-MM-dd"))));

        jtxtTo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("yyyy-MM-dd"))));
        jtxtTo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtxtToFocusLost(evt);
            }
        });

        jLabel2.setText("Usuari");

        jLabel4.setText("Desde yyyy-MM-dd");

        jtxtPersons.setText("0");
        jtxtPersons.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtPersonsActionPerformed(evt);
            }
        });

        jLabel5.setText("Assistents");

        jLabel6.setText("Hasta yyyy-MM-dd");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 899, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jcmbUser, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtxtFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4))
                                .addGap(12, 12, 12)
                                .addComponent(jtxtDays, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtxtTo, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6))
                                .addGap(60, 60, 60)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jtxtPersons, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
                                        .addComponent(jButton1))
                                    .addComponent(jLabel5))))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 719, Short.MAX_VALUE))
                        .addGap(192, 192, 192))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jtxtDays, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxtFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxtTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxtPersons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcmbUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancel)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        // ManagementSpaces remoto = new ManagementSpaces();

        List<Space> SpacesList;
        try {

            List<User> listaUsers;
            listaUsers = Client.remoteMaintenance.GetAllUser();
            cargarComboUsers(jcmbUser, listaUsers);
            SpacesList = Client.remoteMaintenance.GetAllSpacesTable();
            TableModelSpace1 model = new TableModelSpace1(SpacesList);
            jTable2.setModel(model);
            jTable2.setRowSelectionAllowed(true);
            jTable2.setCellSelectionEnabled(false);
        } catch (RemoteException ex) {
            Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_formWindowOpened

    /*
     * Carga la lista que se le envía por parámetro en el combo del parámetro
     */
    private void cargarComboUsers(JComboBox combo, List lista) {
        String item;
        String InactUser = null;
        for (Object obj : lista) {
            InactUser = ((User) obj).getInactivationUser();
            if (InactUser == null || InactUser == "") {
                item = ((User) obj).getUserId() + " | " + ((User) obj).getName().trim();
                combo.addItem(item);
            }
        }
    }

    private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
        int fila = jTable2.rowAtPoint(evt.getPoint());
        int columna = jTable2.columnAtPoint(evt.getPoint());
        if ((fila > -1) && (columna > -1)) {
            try {
                //aqui s'han de llistar just els recursos asociats a l'aula  
                Integer spaceid = (Integer) jTable2.getValueAt(fila, 0);
                activeSpaceId = spaceid;
                List<Resource> ResourcesList = Client.remoteMaintenance.GetAllResourcesFromSpace(spaceid);
                //set the entity objects in the list
                TableModelSpaceResource model = new TableModelSpaceResource(ResourcesList);
                jTable1.setModel(model);
                //jTable1.getRowSelectionAllowed();
                //jTable1.setCellSelectionEnabled(false);
            } catch (RemoteException ex) {
                Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) { //FIXME
                Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jTable2MouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        //FIXME Una vegada confirmada la disponibilitat per part del sistema d'aules es realitzara la reserva     
        int bookingid = 0;         
        try {

            bookingid = Client.remoteConnect.GetNewBookingId();
        } catch (RemoteException ex) {
            Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);
        } catch (EIssueException ex) {
            Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);
        }
        int spaceid = activeSpaceId;
        String userid = Client.availableUser.getUserId();
        String item = jcmbUser.getItemAt(jcmbUser.getSelectedIndex()).toString();
        userid = item.substring(0, item.indexOf("|") - 1);

        CommonLib commonLib = new CommonLib();
        Date startTime = commonLib.stringToDate(jtxtFrom.getText(), "yyyy-MM-dd");
        Date endTime = commonLib.stringToDate(jtxtFrom.getText(), "yyyy-MM-dd");
        

        int pax = Integer.parseInt(jtxtPersons.getText());
        String status = "Enabled";//FIXME
        Date creation_time = new java.sql.Date(System.currentTimeMillis());
        Date record_date = new java.sql.Date(System.currentTimeMillis());

        try {
            Client.remoteConnect.SaveBooking(new Booking(bookingid, userid, spaceid, startTime, endTime, pax, status, creation_time, null, null, record_date));
            AbstractTableModel model = (AbstractTableModel) jTable1.getModel();
            int numRows = jTable2.getSelectedRows().length;
            for (int i = 0; i < numRows; i++) {
                try {
                    Client.remoteConnect.SaveBookingResource(bookingid, (Integer) model.getValueAt(jTable2.getSelectedRow(), 0));
                } catch (RemoteException ex) {
                    Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);
                } catch (EIssueException ex) {
                    Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            double amount = Client.remoteConnect.CalcPrice(bookingid);
            jTextField5.setText(String.valueOf(amount));
            if (Client.remoteConnect.PayBooking(bookingid, amount)){
            JOptionPane.showMessageDialog(null, "Reserva Realizada con éxito");
            }
        } catch (EIssueException ex) {
            Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);

        } catch (RemoteException ex) {
            Logger.getLogger(PanelSearch.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jtxtDaysFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtxtDaysFocusLost
        CommonLib commonLib = new CommonLib();
        Date startTime = commonLib.stringToDate(jtxtFrom.getText(), "yyyy-MM-dd");
        jtxtTo.setText(commonLib.dateToString(commonLib.addDay(startTime, Integer.parseInt(jtxtDays.getText())), "yyyy-MM-dd"));
    }//GEN-LAST:event_jtxtDaysFocusLost

    private void jtxtToFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtxtToFocusLost
        CommonLib commonLib = new CommonLib();
        Date startTime = commonLib.stringToDate(jtxtFrom.getText(), "yyyy-MM-dd");
        Date endTime = commonLib.stringToDate(jtxtTo.getText(), "yyyy-MM-dd");
        Long days = commonLib.calculateDays(startTime, endTime);
        jtxtDays.setText(Long.toString(days + 1));    
    }//GEN-LAST:event_jtxtToFocusLost

    private void jtxtDaysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtDaysActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtDaysActionPerformed

    private void jtxtPersonsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtPersonsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtPersonsActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PanelSearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PanelSearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PanelSearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PanelSearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new PanelSearch(Boolean.TRUE).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JComboBox jcmbUser;
    private javax.swing.JTextField jtxtDays;
    private javax.swing.JFormattedTextField jtxtFrom;
    private javax.swing.JFormattedTextField jtxtPersons;
    private javax.swing.JFormattedTextField jtxtTo;
    // End of variables declaration//GEN-END:variables

    class TableModelSpace1 extends AbstractTableModel {

        List SpacesList;
        //String headerList[] = new String[]{"spaceid", "spacedescription", "capacity", "price_hour", "price_day", "postal_code"};
        String headerList[] = new String[]{"ID", "Description", "Capacity", "Price/hour", "Price/day", "Postal Code"};

        public TableModelSpace1(List list) {
            SpacesList = list;
        }

        @Override
        public int getColumnCount() {
            return 6;
        }

        @Override
        public int getRowCount() {
            return SpacesList.size();
        }
        // this method is called to set the value of each cell

        @Override
        public Object getValueAt(int row, int col) {
            Object returnValue = false;
            //User entity = null;
            Space entity = (Space) SpacesList.get(row);
            switch (col) {
                case 0:
                    returnValue = entity.getSpaceId();
                    break;
                case 1:
                    returnValue = entity.getSpaceDescription();
                    break;
                case 2:
                    returnValue = entity.getCapacity();
                    break;
                case 3:
                    returnValue = entity.getPriceDay();
                    break;
                case 4:
                    returnValue = entity.getPriceHour();
                    break;
                case 5:
                    returnValue = entity.getPostalCode();
                    break;
            }
            return returnValue;
        }
        //display the name of columns

        @Override
        public String getColumnName(int col) {
            return headerList[col];
        }
    }

    class TableModelSpaceResource extends AbstractTableModel {

        List ResourcesList;
        String c1 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC1);
        String c2 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC2);
        String c3 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC3);
        String c4 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC4);
        String c5 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC5);
//    String headerList[] = new String[]{c1, c2, c3, c4, c5};
        String headerList[] = new String[]{"ID", "Description", "Amount", "price/Hour", "price/Day"};

        public TableModelSpaceResource(List list) {
            ResourcesList = list;
        }

        @Override
        public int getColumnCount() {
            return 5;
        }

        @Override
        public int getRowCount() {
            return ResourcesList.size();
        }
        // this method is called to set the value of each cell

        @Override
        public Object getValueAt(int row, int col) {
            Object returnValue = false;
            //User entity = null;
            Resource entity = (Resource) ResourcesList.get(row);
            switch (col) {
                case 0:
                    returnValue = entity.getResourceId();
                    break;
                case 1:
                    returnValue = entity.getResourceDescription();
                    break;
                case 2:
                    returnValue = entity.getAmount();
                    break;
                case 3:
                    returnValue = entity.getPriceHour();
                    break;
                case 4:
                    returnValue = entity.getPriceDay();
                    break;
            }
            return returnValue;
        }
        //display the name of columns

        @Override
        public String getColumnName(int col) {
            return headerList[col];
        }
    }
}
